<?php

/**
 * Controller.php
 *
 * Holds abstract class Controller
 *
 * @package Application
 * @subpackage Controllers
 */

/**
 * Controller
 *
 * Application specific base controller
 *
 * @package Application
 * @subpackage Controllers
 */
abstract class Controller extends Mvc_Controller_Base {

	//	protected $content_type_header = 'application/xhtml+xml; charset=ISO-8859-1';
	protected $content_type_header = 'text/html; charset=UTF-8';
	
	protected $content_type_header_list = array(
		"Smarty"	=> "text/html; charset=UTF-8",
		"PureJSON"	=> "application/json"
	);

	/**
	 * Initializes page
	 *
	 * @return Controller (fluent interface)
	 */
	public function init() {
		// Set output type
		$this->setView($this->_view);
		
		return $this;
	}
	
	protected function setView($view){
		$this->_view = $view;
		
		if( isset($this->content_type_header_list[$view]) ){
			$this->content_type_header = $this->content_type_header_list[$view];
		}
		
		$this->getResponse()->setHeader('Content-type', $this->content_type_header);
	}
	
	
	/**
	 * Simple helper function
	 *
	 * Set view to PureJSON, unset all previously assigned variables
	 */
	protected function setPureJSON(){
		//Make sure all previously assigned variables are unset,
		//as we don't want specific user information to be JSON encoded.
		//The controller should provide all relevant JSON data after calling unSetAll();
		$this->unSetAll();
		$this->setView("PureJSON");
		$this->success = false;
	}
}
